//
//  UILabel+Convenience.m
//  PCCategoriesDemo
//
//  Created by snack on 14-4-8.
//  Copyright (c) 2014年 宋鹏程. All rights reserved.
//

#import "UILabel+Convenience.h"
#import "UIView+Convenience.h"

@implementation UILabel (Convenience)

- (void)addTarget:(id)target action:(SEL)action
{
    [self setUserInteractionEnabled:YES];
    UIControl *actionView = [[UIControl alloc] initWithFrame:self.bounds];
    actionView.backgroundColor = PCColorClear;
    [self addSubview:actionView];
    [self sendSubviewToBack:actionView];
    
    [actionView addTarget:self action:@selector(appendHighlightedColor) forControlEvents:UIControlEventTouchDown | UIControlEventTouchDragEnter];
    [actionView addTarget:self action:@selector(removeHighlightedColor) forControlEvents: UIControlEventTouchDragOutside| UIControlEventTouchUpInside | UIControlEventTouchUpOutside | UIControlEventTouchCancel];
    
    [actionView addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
}

- (void)appendHighlightedColor
{
    self.backgroundColor = PCColorRed;
}

- (void)removeHighlightedColor
{
    self.backgroundColor = [UIColor clearColor];
}

- (void)setTextToAdjustSize:(NSString *)text
{
    self.numberOfLines = 0;
    self.lineBreakMode = NSLineBreakByCharWrapping;
    self.textAlignment = NSTextAlignmentLeft;
    if(text) self.text = text;
    self.frameSize = [self.text boundingRectWithFont:self.font width:self.frameWidth];
}

- (void)showUnderLine:(BOOL)show
{
    [self setTextToAdjustSize:self.text];
    
}
@end
